package com.shrio.service;

import com.shrio.dao.MemberDao;
import com.shrio.entity.Member;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import redis.clients.jedis.ShardedJedis;
import redis.clients.jedis.ShardedJedisPool;

import java.util.List;

/**
 * Created by luojie on 2018/3/14.
 */
@Service("openVirtualService")
public class QuartzTest {

    private static int i= 1;
    @Autowired
    private MemberDao memberDao;
    @Autowired
    private ShardedJedisPool shardedJedisPool;
    public void operate(){ //虚机开通
        //业务逻辑
        ShardedJedis jds = shardedJedisPool.getResource();
        Long result = jds.setnx("james", "test");
        jds.expire("james", 10);
        System.out.println("---redis----"+ result);
        if(result == 1){
            List<Member> list = memberDao.findAll();
            for(Member member : list){
                member.setBalance(member.getBalance() + 10);
                memberDao.update(member);
            }
            System.out.println("第"+ i++ + "次执行操作");
        }


    }
}
